package com.plate.bpm.web.controller;

import java.util.List;

import javax.annotation.Resource;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricVariableInstance;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 *作者： 李志刚
 *时间：2015年9月2日
 */
public class WorkspaceController {
	private ProcessEngine processEngine;
	
	/**
     * 查看历史【包含流程跟踪、任务列表（完成和未完成）、流程变量】
     * 
     * @return
     */
    @RequestMapping("process-viewHistory")
    public String viewHistory(
            @RequestParam("processInstanceId") String processInstanceId,
            Model model) {
        HistoryService historyService = processEngine.getHistoryService();
        List<HistoricTaskInstance> historicTasks = historyService
                .createHistoricTaskInstanceQuery()
                .processInstanceId(processInstanceId).list();
        List<HistoricVariableInstance> historicVariableInstances = historyService
                .createHistoricVariableInstanceQuery()
                .processInstanceId(processInstanceId).list();
        model.addAttribute("historicTasks", historicTasks);
        model.addAttribute("historicVariableInstances",
                historicVariableInstances);

        return "managerflow/viewHistory";
    }
    
    /**
   	 * @param 对processEngine进行赋值
   	 */
   	@Resource
   	public void setProcessEngine(ProcessEngine processEngine) {
   		this.processEngine = processEngine;
   	}
}

	